package com.example.myxmpp;

import android.content.ContentValues;
import android.database.Cursor;
import android.util.Log;

import androidx.test.runner.AndroidJUnit4;

import com.example.myxmpp.dbhelper.ContactOpenHelper;
import com.example.myxmpp.provider.ContactsProvider;

import org.junit.Test;
import org.junit.runner.RunWith;

import static androidx.test.InstrumentationRegistry.getContext;


@RunWith(AndroidJUnit4.class)
public class TextContactsProvider{
    @Test
    public void testInsert(){
        ContentValues values = new ContentValues();
        values.put(ContactOpenHelper.ContactTable.ACCOUNT,"billy@163.com");
        values.put(ContactOpenHelper.ContactTable.NICKNAME,"老伍");
        values.put(ContactOpenHelper.ContactTable.AVATAR,"0");
        values.put(ContactOpenHelper.ContactTable.PINYIN,"laowu");
       getContext().getContentResolver().insert(ContactsProvider.URI_CONTACT,values);
    }

    @Test
    public void testDelete(){
        getContext().getContentResolver().delete(ContactsProvider.URI_CONTACT,ContactOpenHelper.ContactTable.ACCOUNT +"=?",
                new String[]{"billy@163.com"});
    }

    @Test
    public void testUpdate(){
        ContentValues values = new ContentValues();
        values.put(ContactOpenHelper.ContactTable.ACCOUNT,"billy@163.com");
        values.put(ContactOpenHelper.ContactTable.NICKNAME,"我是老伍");
        values.put(ContactOpenHelper.ContactTable.AVATAR,"0");
        values.put(ContactOpenHelper.ContactTable.PINYIN,"woshilanwu");

        getContext().getContentResolver().update(ContactsProvider.URI_CONTACT,values,ContactOpenHelper.ContactTable.ACCOUNT + "=?",
                new String[]{"billy@163.com"});
    }

    @Test
    public void testQuery(){
       Cursor cursor = getContext().getContentResolver().query(ContactsProvider.URI_CONTACT,null,null,null);
       int columnCount = cursor.getColumnCount();
       while (cursor.moveToNext()){
           for (int i = 0; i < columnCount;i++ ){
               Log.i("textQuery","==========="+cursor.getString(i)+"=========");
           }
       }
    }

}
